[feat] support Kubernetes Gateway API - #6347
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Kubernetes Gateway API (gateway.networking.k8s.io/v1) support to ShenYu’s k8s controller/starter, alongside existing Ingress support, and introduces a new integrated test workflow to validate Gateway API routing.
Changes:
- Adds Spring Boot auto-configuration and controllers/reconcilers for
GatewayClass,Gateway, andHTTPRoute. - Implements
HttpRouteParser+GatewayRouteCacheto translate HTTPRoute specs into ShenYu selector/rule config and track bindings. - Introduces a new k8s Gateway API integrated test module and GitHub Actions workflow to run it on kind.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports | Registers the new Gateway API auto-configuration. |
| shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/resources/META-INF/spring.factories | Registers Gateway API auto-configuration for legacy Spring Boot loading. |
| shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/IngressControllerConfiguration.java | Adds shenyu.k8s.mode gating and fixes default secret TLS loading condition. |
| shenyu-spring-boot-starter/shenyu-spring-boot-starter-k8s/src/main/java/org/apache/shenyu/springboot/starter/k8s/GatewayApiControllerConfiguration.java | New Gateway API controller wiring (informers/controllers/reconcilers/repository bootstrap). |
| shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/reconciler/GatewayClassReconciler.java | New GatewayClass reconciliation + status patch + requeue logic. |
| shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/reconciler/GatewayReconciler.java | New Gateway reconciliation, status patching, and HTTPRoute requeueing. |
| shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/reconciler/HTTPRouteReconciler.java | New HTTPRoute reconciliation, config apply/delete, binding, and status patching. |
| shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/parser/HttpRouteParser.java | New HTTPRoute→selector/rule translation logic. |
| shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/common/GatewayApiConstants.java | Gateway API constants + shared condition helper. |
| shenyu-kubernetes-controller/src/main/java/org/apache/shenyu/k8s/cache/GatewayRouteCache.java | New thread-safe cache for route↔selector and gateway↔route bindings. |
| shenyu-kubernetes-controller/src/test/java/org/apache/shenyu/k8s/GatewayReconcilerTest.java | Unit tests for Gateway reconciliation behaviors. |
| shenyu-kubernetes-controller/src/test/java/org/apache/shenyu/k8s/HTTPRouteReconcilerTest.java | Unit tests for HTTPRoute reconciliation behaviors. |
| shenyu-kubernetes-controller/src/test/java/org/apache/shenyu/k8s/HttpRouteParserTest.java | Unit tests for HTTPRoute parsing/mapping logic. |
| shenyu-integrated-test/pom.xml | Adds the new Gateway API integrated test module to the build. |
| shenyu-integrated-test/shenyu-integrated-test-k8s-gateway-api-http/** | New integrated test module (app, config, Dockerfile, kind manifests, scripts, tests). |
| shenyu-examples/shenyu-examples-http/k8s/gateway-api.yml | Example GatewayClass/Gateway/HTTPRoute manifests for the HTTP example. |
| .github/workflows/integrated-test-k8s-gateway-api.yml | New CI workflow to run Gateway API integrated tests on kind. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Aias00
left a comment
There was a problem hiding this comment.
Thanks for this — the Gateway API support is a solid addition and the test scaffolding is appreciated. A few correctness/operational issues before merge:
Blocker — non-idempotent HTTPRoute reconcile. HTTPRouteReconciler.reconcile (HTTPRouteReconciler.java:2192-2195) unconditionally does deleteConfig → parse → applyConfig on every pass, and HttpRouteParser allocates fresh selector/rule IDs from a monotonic AtomicLong on each parse (GatewayRouteCache.java:1127-1133). Because the informer resyncs every 1 min (GatewayApiControllerConfiguration, withResyncPeriod(Duration.ofMinutes(1))), every HTTPRoute is re-reconciled each minute: the old selector/rule IDs are deleted and new ones created even when the spec is unchanged. ShenyuCacheRepository.saveOrUpdateSelectorData then pushes delete+create into the live data-plane cache, so there's a brief window per route per minute where matching requests find no selector. The Ingress reconciler avoids this by only re-applying when needUpdate(old, current) is true (IngressReconciler.java:175). Suggest either reusing deterministic IDs derived from (namespace, routeName, ruleIndex, hostname) or skipping re-apply when the parsed config is unchanged, and adding a test that asserts IDs are stable across two reconcile() calls.
Blocker — own e2e is red. The new it-k8s-gateway-api workflow fails on this head (build (shenyu-integrated-test-k8s-gateway-api-http) FAILURE, run 29428497010). Please grab the controller logs from the workflow's debug step and fix or explain.
Should fix.
GatewayReconciler.isShenyuGatewaycomparesspec.gatewayClassNameto the literal"shenyu"instead of resolving the GatewayClass and checking itsspec.controllerName(GatewayClassReconciler already has the correct check). Gateways whose GatewayClass has any other name are silently ignored even when that class is ShenYu-owned.- Cross-namespace
parentRefsare accepted without aReferenceGrantcheck, andResolvedRefs=Trueis reported unconditionally — including when backend endpoints are missing/unresolvable (HttpRouteParser.parseBackendRefs logs and skips, thenupdateHTTPRouteStatusstill emitsResolvedRefs=True). The latter also programs a divide selector withhandle="[]", so requests 5xx while status claims healthy. bindToGatewaybinds to non-ShenYu parents too, and the Gateway deletion path callsdeleteAssociatedRouteswithout verifying the deleted Gateway was ShenYu-managed — deleting a non-ShenYu gateway of the same name can wipe selectors for a route still served by a ShenYu gateway.GatewayReconciler.requeueAffectedHTTPRoutesdoes a full cluster-wide HTTPRoute scan on every (resync) reconcile; should only run when the Gateway actually changed.- No leader election; multi-replica deployments will race on status patches and double-reconcile. Either wire leader election or document single-replica-only.
- Wildcard hostnames (
*.example.com) are matched withOperatorEnum.EQ(HttpRouteParser.processRule:1340-1348) — they will never match subdomains. Please emit a domain pattern operator for wildcard hostnames. GatewayClassReconciler.updateGatewayClassAcceptedStatusrebuilds theconditionsarray from scratch; merge-patch replaces arrays wholesale, so it clobbers conditions set by other controllers. Mirror the preservation logic already used for Gateway status.
Minor: the MapUtils.isEmpty → isNotEmpty fix in IngressControllerConfiguration.tcpSslContextSpec is a real and correct bug fix (current master is inverted), but it's unrelated to the Gateway API feature — please split into its own commit/PR for traceability.
For reference I reviewed the full diff (head 19e8bd8) plus the existing IngressReconciler/ShenyuCacheRepository in the local tree; did not modify anything.
close #6346
Implements ShenYu support for Kubernetes Gateway API (gateway.networking.k8s.io/v1), complementing the existing Ingress support.
Core Components
GatewayClassReconcilerspec.controllerName=shenyuGatewayReconcilerHTTPRouteReconcilerHttpRouteParserHttpRouteParserSelectorData/RuleDataGatewayRouteCacheGatewayApiControllerConfigurationMake sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.